package data_report

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/rpc-client/analysisClient/rpc"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type DailySummaryReportLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 每日汇总报表
func NewDailySummaryReportLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DailySummaryReportLogic {
	return &DailySummaryReportLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *DailySummaryReportLogic) DailySummaryReport(req *types.DailyReportRequest) (resp types.DailyReportResponse, err error) {

	resp = types.DailyReportResponse{
		Data:     make([]types.DailyReportData, 0),
		Page:     req.Page,
		PageSize: req.PageSize,
		Total:    0,
	}

	reqq := &rpc.DailyReportRequest{
		StartTime: req.StartTime,
		EndTime:   req.EndTime,
		Page:      req.Page,
		PageSize:  req.PageSize,
	}

	analysis, err := l.svcCtx.Analysis.ArDayAperationAnalysis(l.ctx, reqq)
	if err != nil {
		return resp, err
	}

	for _, v := range analysis.Data {
		t := types.DailyReportData{
			Date:                v.Date,
			RegisterTotal:       v.RegisterTotal,
			Bet:                 v.Bet,
			Fee:                 v.Fee,
			Prize:               v.Prize,
			SafeBoxIncome:       v.SafeBoxIncome,
			RechargeSuccess:     v.RechargeSuccess,
			WithdrawSuccess:     v.WithdrawSuccess,
			OrderRebates:        v.OrderRebates,
			FirstChargeRebates:  v.FirstChargeRebates,
			RedPacket:           v.RedPacket,
			DailySign:           v.DailySign,
			AgentRedPacket:      v.AgentRedPacket,
			ChargeGift:          v.ChargeGift,
			RegisterGift:        v.RegisterGift,
			ManualChargeGift:    v.ManualChargeGift,
			FirstFill:           v.FirstFill,
			PlatformNetIncome:   v.PlatformNetIncome,
			GameWinLose:         v.GameWinLose,
			PlatformNetEarnings: v.PlatformNetEarnings,
		}
		resp.Data = append(resp.Data, t)
	}
	resp.Total = analysis.Total
	return
}
